package com.sakura.controller;

import com.github.pagehelper.PageInfo;
import com.sakura.po.Actor;
import com.sakura.po.BeComment;
import com.sakura.po.Reply;
import com.sakura.service.ReplyService;
import com.sakura.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@Controller
public class ReplyController {
    @Autowired
    private ReplyService replyService;
    @GetMapping(value = "/replyIndex")
    public String replyIndex (Model model){
        List<Reply> mlist=replyService.getRlyCountByNum();
        model.addAttribute("mlist",mlist);

        return "reply/replyIndex";

    }
    @GetMapping("/addreply")
    public String addreply(){ return"reply/addReply"; }
    @ResponseBody
    @RequestMapping("/addReplySubmit")
    public R addReplySubmit(@RequestBody Reply reply){
        replyService.addReplySubmit(reply);
        return R.ok();
    }
    @ResponseBody
    @RequestMapping("/deleteReplyByIds")
    public R deleteReplyByIds(String ids){
        List list
                = Arrays.asList(ids.split(","));
        replyService.deleteReplyByIds(list);
        return R.ok();
    }

    @GetMapping("/queryReplyById")
    public String queryReplyById(Model model, Integer id){
        //根据id获取对象
        Reply rly= replyService.queryReplyById(id);
        model.addAttribute("rly",rly);
        return "reply/updateReply";
    }
    @ResponseBody
    @RequestMapping("/updateReplySubmit")
    public R updateReplySubmit(@RequestBody Reply reply){

        replyService.updateReplySubmit(reply);
        return R.ok();
    }

    @ResponseBody
    @RequestMapping( "/getAllReply")
    public R getAllReply(Reply reply,
                              @RequestParam(defaultValue = "1") Integer page,
                              @RequestParam(defaultValue = "15") Integer limit){
        PageInfo<Reply> pageInfo=replyService.getAllReply(reply,page,limit);
        return  R.ok("成功",pageInfo.getTotal(),pageInfo.getList());
    }
}
